﻿namespace LogManager.Core.Factories
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Xml.Linq;
    using LogManager.Core.Models;
    using LogManager.Core.Models.Smtp;
    using LogManager.Core.Providers;

    public abstract class XmlElementFactoryBase : IXmlElementFactory
    {
        public abstract IXmlTemplateProvider TemplateProvider { get; protected set; }

        public virtual Configuration CreateConfiguration(string xmlPath, string xsdPath)
        {
            var baseDocument = Configuration.LoadFile(xmlPath, xsdPath);
            return this.CreateConfiguration(baseDocument);
        }

        public virtual Configuration CreateNewConfiguration()
        {
            return this.CreateConfiguration(this.TemplateProvider.ConfigurationTemplate);
        }

        public virtual Location CreateNewLocation(IServer parent)
        {
            return this.CreateLocation(this.TemplateProvider.LocationTemplate, parent);
        }

        public virtual Server CreateNewServer(IPlateform parent)
        {
            return this.CreateServer(this.TemplateProvider.ServerTemplate, parent);
        }

        public virtual Plateform CreateNewPlateform(IWarehouse parent)
        {
            return this.CreatePlateform(this.TemplateProvider.PlateformTemplate, parent);
        }

        public virtual Warehouse CreateNewWarehouse(IConfiguration parent)
        {
            return this.CreateWarehouse(this.TemplateProvider.WarehouseTemplate, parent);
        }

        public abstract Location CreateLocation(XElement baseNode, IServer parent);
        public abstract Server CreateServer(XElement baseNode, IPlateform parent);
        public abstract Plateform CreatePlateform(XElement baseNode, IWarehouse parent);
        public abstract Warehouse CreateWarehouse(XElement baseNode, IConfiguration parent);
        public abstract Configuration CreateConfiguration(XDocument baseDocument);
        public abstract Settings CreateSettings(XElement baseNode);
        public abstract SmtpSettings CreateSmtpSettings(XElement baseNode);
        public abstract SmtpServer CreateSmtpServer(XElement baseNode);
        public abstract From CreateSmtpFrom(XElement baseNode);
        public abstract To CreateSmtpTo(XElement baseNode);
    }
}
